package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@HttpInlet(Conn.INLET_PRODUCT_QUERY)
public class GetProductQuery extends JTAsyGet<GetProductQuery.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String carshopId;

    public GetProductQuery(String carshopId,AsyCallBack<Info> asyCallBack) {
        super(asyCallBack);

        this.carshopId = carshopId;

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        info.name = body.optString("name");

        info.phone = body.optString("phone");

        info.address = body.optString("address");

        info.logo = body.optString("logo");

        info.lon = body.optString("lon");

        info.lat = body.optString("lat");

        JSONArray list = body.optJSONArray("mapList");

        for (int i = 0; i < list.length(); i++) {

            JSONObject object1 = list.optJSONObject(i);

            GoodsList goodsList = new GoodsList();

            if(i==0)

                goodsList.isSelect = true;

            else

                goodsList.isSelect = false;

            goodsList.TYPENAME = object1.optString("TYPENAME");

            goodsList.TYPEID = object1.optString("TYPEID");

            JSONArray goods_list = object1.optJSONArray("goodsList");

            for (int j = 0; j < goods_list.length(); j++) {

                JSONObject object2 = goods_list.optJSONObject(j);

                NameList nameList = new NameList();

                nameList.GOODS_IMG = object2.optString("GOODS_IMG");

                nameList.ID = object2.optString("ID");

                nameList.NAME = object2.optString("NAME");

                nameList.PRICE = object2.optString("PRICE");

                goodsList.nameLists.add(nameList);

            }

            info.list1.add(goodsList);
        }

        return info;

    }

    public static class Info implements Serializable {

        public String msg;

        public String name,phone,address,logo,lon,lat;

        public List<GoodsList> list1 = new ArrayList<>();

    }

    public static class GoodsList implements Serializable {

        public boolean isSelect;

        public String TYPENAME;

        public String TYPEID;

        public List<NameList> nameLists = new ArrayList<>();


    }
    public static class NameList implements Serializable{
        public String ID;
        public String NAME;
        public String PRICE;
        public String GOODS_IMG;
        public int NUM = 0;
    }
}
